var jdate=function (format, timestamp)
{ 
	var re;
	if (timestamp&&(re=/(\d+)-(\d+)-(\d+)/.exec(timestamp))) 
		timestamp=re[2] + '/' + re[3] + '/' + re[1]; 
	if (timestamp&&(re=/^(\d+):(\d+):(\d+)$/.exec(timestamp))) 
		timestamp='1/1/1970 ' + timestamp; 
		
	 
		
	var a,o='',f={
		date:timestamp?new Date(timestamp):new Date(),
		leading:function(x){ return parseInt(x,10)<10?('0'+x):x;}, 
		month:['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
		day:['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
		
		// formats
		d:function() { return this.leading(this.date.getDate()); }, 
		D:function() { return this.day[this.date.getDate()].substr(0,3); },
		j:function() { return this.date.getDate(); } , 
		l:function() { return this.day[this.date.getDate()]; }, 
		N:function() { return this.date.getDay() + 1; }, 
		S:function() { var i=['st','nd','rd'],x=this.date.getDay(); return x<3?i[x]:'th'; }, 
		w:function() { return this.date.getDay(); }, 
		F:function() { return this.month[this.date.getMonth()]; },
		m:function() { return this.leading(this.n()); },
		M:function() { return this.month[this.date.getMonth()].substr(0,3); },
		n:function() { return this.date.getMonth() + 1; },
		Y:function() { return this.date.getFullYear(); },
		y:function() { return this.date.getYear() ; },
		A:function() { var i=this.date.getHours(); return i<12?'AM':'PM' ; },
		a:function() { return this.A().toLowerCase(); },
		G:function() { return this.date.getHours(); },
		g:function() { var i=this.G(); return i>12?(i-12):i; },
		H:function() { return this.leading(this.G()); },
		h:function() { return this.leading(this.g()); },
		i:function() { return this.leading(this.date.getMinutes()); } ,
		s:function() { return this.leading(this.date.getSeconds()); } ,
		u:function() { return this.leading(this.date.getMilliseconds()); } ,
		c:function() { return this.date.toString(); } ,
		r:function() { return this.c(); } ,
		U:function() { return this.date.getTime(); } 
	}
	
	if (isNaN(f.date))
	{
		return '<font color="red">' + timestamp + '</font>';
	}
	
	for (var x=0;x<format.length;x++)
	{
		a=format.substr(x,1);
		o+=f[a]?f[a]():a; 
	}
	return ''+o+'';
}